// auth.js
export const saveUserInfo = (username, password, rememberMe) => {
  localStorage.setItem('username', username); // 始终保存 username
  if (rememberMe) { // 如果选择了记住我，才保存 password
    localStorage.setItem('password', password);
    localStorage.setItem('rememberMe', 'true');
  } else {
    localStorage.removeItem('password'); // 清除 password
    localStorage.removeItem('rememberMe'); 
  }
};

  
  export const clearUserInfo = () => {
    // 从 localStorage 中清除用户名、密码和记住我的状态
    localStorage.removeItem('username');
    localStorage.removeItem('password');
    localStorage.removeItem('rememberMe');
  };
  
  export const getUserInfo = () => {
    // 从 localStorage 获取保存的用户信息
    const username = localStorage.getItem('username');
    const password = localStorage.getItem('password');
    const rememberMe = localStorage.getItem('rememberMe') === 'true';
  
    return { username, password, rememberMe };
  };
  
  export const setToken = (token) => {
    // 将令牌保存到 localStorage 或 sessionStorage
    sessionStorage.setItem('token', token);
  };
  
  export const getToken = () => {
    // 从 localStorage 获取令牌
    //console.log( localStorage.getItem('token'))
    return sessionStorage.getItem('token');
  };
  
  export const clearToken = () => {
    // 从 localStorage 中清除令牌
    sessionStorage.removeItem('token');
  };